package com.liusuai.yixian.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class LoginConfiguration implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;
    @Autowired
    private UrlInterceptor urlInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //url 拦截器
//        InterceptorRegistration urlRegistry = registry.addInterceptor(urlInterceptor);
//        urlRegistry.addPathPatterns("/**");

        // 注册拦截器
        InterceptorRegistration loginRegistry = registry.addInterceptor(loginInterceptor);

        // 拦截路径
        loginRegistry.addPathPatterns("/**");
        // 排除路径
        loginRegistry.excludePathPatterns("/")
                .excludePathPatterns("/web/login")
                .excludePathPatterns("/login")
                .excludePathPatterns("/hello")
                .excludePathPatterns("/getNewVersionInfo")
                .excludePathPatterns("/download/**")
                .excludePathPatterns("/download/local/**")
                // 排除资源请求
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/static/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/img/**")
                .excludePathPatterns("/voices/**")
                .excludePathPatterns("/localdesk/**");


    }

}
